package com.iflytek.ssm.erp.service.impl;

import com.iflytek.ssm.erp.dao.CustomerMapper;
import com.iflytek.ssm.erp.entity.Customer;
import com.iflytek.ssm.erp.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    /**
     * 根据ID删除客户信息
     * @param id
     * @return
     */
    public boolean deleteById(Integer id) {

        int num = customerMapper.deleteById(id);
        if (num > 0) {
            return true;
        }
        return false;
    }

    /**
     * @param customer
     * @return
     */
    public boolean addCustomer(Customer customer) {
        int num = customerMapper.addCustomer(customer);
        if (num > 0) {
            return true;
        }
        return false;
    }

    /**
     * @param name
     * @param contactPerson
     * @param mobile
     * @param phon
     * @return
     */
    public List<Customer> list(String name, String contactPerson, String mobile, String phone) {

        Customer customer = new Customer();
        customer.setName(name);
        customer.setContactPerson(contactPerson);
        customer.setMobile(mobile);
        customer.setPhone(phone);

        List<Customer> list  =customerMapper.list(customer);
        if (list != null) {
            return list;
        }
        return Collections.emptyList();
    }

    /**
     * @param id
     * @return
     */
    public Customer queryById(Integer id) {
        Customer customer = customerMapper.getById(id);
        if (customer != null) {
            return customer;
        }
        return null;
    }

    /**
     * @param customer
     * @return
     */
    public boolean updateCustomer(Customer customer) {
        int num = customerMapper.updateCustomer(customer);
        if (num > 0) {
            return true;

        }
        return false;
    }

}
